package com.dragon.client.controller.contract;

import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.contract.IProduceProductsService;
import com.dragon.repository.domain.dto.ProduceProductsDTO;
import com.dragon.repository.domain.vo.ProduceProductsVO;
import com.dragon.repository.entity.ProduceProducts;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * <p>
 * 供应商产品生产关联表 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-08-23
 */
@RestController
@RequestMapping("produceProducts")
@Api(tags = "生产单产品管理")
public class ProduceProductsController {

    @Autowired
    IProduceProductsService service;


    @GetMapping("list")
    @ApiOperation(value = "根据生产单id获取列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "produceId",required = true,type = "int",value = "生产id"),
            @ApiImplicitParam(name = "page",required = true,type = "int",value = "页码"),
            @ApiImplicitParam(name = "limit",required = true,type = "int",value = "条数")
    })
    public ResponseData selectList(@RequestParam Integer produceId,
                                   @RequestParam Integer page,
                                   @RequestParam Integer limit){
        List<ProduceProducts> produceProducts = service.selectList(produceId,page,limit);
        return ResponseData.success(ProduceProductsDTO.convertList(produceProducts));
    }

    @GetMapping("productsList")
    @ApiOperation(value = "根据生产单获取产品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deliverId",required = true,type = "int",value = "收货id"),
            @ApiImplicitParam(name = "page",required = true,type = "int",value = "页码"),
            @ApiImplicitParam(name = "limit",required = true,type = "int",value = "条数")
    })
    public ResponseData selectProductsList(@RequestParam Integer deliverId,
                                   @RequestParam Integer page,
                                   @RequestParam Integer limit){
        List<ProduceProducts> produceProducts = service.selectProductsList(deliverId,page,limit);
        return ResponseData.success(ProduceProductsDTO.convertList(produceProducts));
    }

    @GetMapping("export")
    @ApiOperation(value = "导出生产单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "produceId",required = true,type = "int",value = "生产单Id"),
    })
    public void exportExcel(
            @RequestParam Integer produceId,
            @ApiParam(hidden = true) HttpServletResponse response
            )throws UnsupportedEncodingException {
        service.exportExcel(produceId,response);
        //return ResponseData.success();
    }



    @PostMapping("updateStatus")
    @ApiOperation(value = "修改状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", required = true, type = "int", value = "产品子表id"),
            @ApiImplicitParam(name = "status", required = true, type = "int", value = "状态")
    })
    public ResponseData updateStatus(@RequestParam Integer id, @RequestParam Integer status) {
        service.updateProduceStatus(id, status);
        return ResponseData.success();
    }


    @PostMapping("enter")
    @ApiOperation(value = "录入生产数据")
    public ResponseData enterProductNum(@RequestBody ProduceProductsVO pp){
        service.enterProductNum(ProduceProductsVO.convert(pp));
        return ResponseData.success();
    }



}
